/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import conexion.ConexionFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import modelos.DetalleOrden;


/**
 *
 * @author luramirez
 */
public class DetalleOrdenDao implements IOrdersDetail{

    @Override
    public List<DetalleOrden> getDetalleOrden(Integer id) throws Exception {
        Connection sqlc = null;
        List<DetalleOrden> result = null;
        ResultSet rs = null;
        PreparedStatement pstmt = null;

        try {

            sqlc = ConexionFactory.getInstance().getConexion();
            pstmt = sqlc.prepareStatement("SELECT * FROM vw_Order_Detail WHERE idOrden = "+id);
            rs = pstmt.executeQuery();
            // inicializar la lista como vacia
            result = new ArrayList<>();

            // mapea (pasa/copia) los registros resultantes SQL a la lista
            while (rs.next()) {
                DetalleOrden objUsuario = Helper.getOrdenDetail(rs, this);
                result.add(objUsuario);
            }
            
        } catch (NullPointerException ex) {
            throw new Exception("La Conexion es Nula o Hay Problemas en la Red.");
        } catch (Exception ex) {
            throw new Exception(ex.getCause().getMessage());

        }
        return result;
    }
    
}
